#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "crypto/errors.h"

int JsonKeyHash(char *key)
{
    const int base = 129;
    int len = strlen(key), num = 0;
    for (int i = 0; i < len; i++)
        num = num * base + (int)key[i]; // 权值展开
    return num;
}

int main()
{
    int hash[32];
    char randomString[8];
    int fd = open("/dev/urandom", O_RDONLY);
    if (fd == -1)
    {
        export(CODE_FILE_OPERATE_FAILED, "File /dev/urandom open failed!");
    }
    int i = 0;
    while (i != 32)
    {
        hash[i] = 0;
        i++;
    }
    for (int i = 0; i < 100000; i++)
    {
        int ret = read(fd, randomString, 7);
        assert(ret != 0);
        hash[JsonKeyHash(randomString) & (32 - 1)]++;
    }
    i = 0;
    while (i != 32)
    {
        printf("%d\n", hash[i]);
        i++;
    }
}